package com.ruoyi.wechat.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.wechat.domain.Product;
import com.ruoyi.wechat.domain.Project;
import com.ruoyi.wechat.domain.WxProject;
import com.ruoyi.wechat.domain.WxScenicSpots;
import com.ruoyi.wechat.service.IProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "微信小程序API-商品管理", tags = {"微信小程序API-商品管理"})
@RestController
@RequestMapping("/wechat/product")
public class WxProductController extends BaseController {
    @Autowired
    private IProductService wxproductService;

    /**
     * 按条件搜索商品
     * @param product 商品
     * @return 列表
     */
    @ApiOperation(value = "按条件搜索商品列表", response = Product.class)
    @GetMapping("/list")
    public AjaxResult list(Product product) {
        List<Product> list  = wxproductService.selectProductList(product);
        return success(list);
    }
    @ApiOperation(value = "根据营地Id获取该营地下的商品列表", response = WxScenicSpots.class)
    @GetMapping("/getInfoByCampId/{campId}")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
//    })
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<Product> list = wxproductService.getInfoByCampId(campId);
        return success(list);
    }
    /**
     * 获取商品详细信息
     */
    @ApiOperation(value = "根据商品id获取详细信息", response = Product.class)
    @ApiParam(required = true, value = "直接传入id")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") String productId)
    {
        return success(wxproductService.selectProductByProductId(productId));
    }
//    /**
//     * 新增商品
//     */
//    @ApiOperation(value = "新增商品")
//    @PostMapping
//    public AjaxResult add(@RequestBody Product product)
//    {
//        return toAjax(wxproductService.insertProduct(product));
//    }
    /**
     * 新增商品
     */
    @ApiOperation(value = "新增商品")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Product product)
    {
        return success(wxproductService.insertProduct(product));
    }
    /**
     * 修改商品
     */
    @ApiOperation(value = "修改商品")
    @PutMapping
    public AjaxResult edit(@RequestBody Product product)
    {
        return toAjax(wxproductService.updateProduct(product));
    }

    /**
     * 删除商品
     */

    @ApiOperation(value = "删除商品")
    @DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable String[] productIds)
    {
        return toAjax(wxproductService.deleteProductByProductIds(productIds));
    }
}

